# /bin/bash

# example ./test.sh -c 1,2,3,4,5 -r 1,2 -l ./test.log

outputfile=
concurrent=
reps=

while getopts ":qvc:r:l:" OPTION 
do
		case "${OPTION}" in
		"q")
				echo "quiet"
				;;
		"v")
				echo "verbose"
				;;
		"c")
				concurrent=$(echo $OPTARG | tr "," "\n")
				;;
		"r")
				reps=$(echo $OPTARG | tr "," "\n")
				;;
		"l")
				outputfile=$OPTARG
				;;
		*)
				echo "unkonwn option"
				;;
		esac
done

# echo $outputfile $concurrent $reps

# echo -e "测试日期							请求次数		 		总时间				数据传输量		响应时间		 完成请求数/秒	 数据传输/秒		 实际并发量		 成功请求		失败请求" >> ${outputfile}
echo -e "    参数    |       测试日期       | 请求次数 | 总时间	 |  数据传输量 	| 响应时间 | 完成请求数/秒 | 数据传输/秒	| 实际并发量 | 成功请求 | 失败请求|" >> ${outputfile}
echo -e "----------------------------------------------------------------------------------------------------------------------------------------" >> ${outputfile} 

# for ((i=0; i<${#reps[@]}; i++)); do
    # for ((j=0; j<${#concurrent[@]}; j++)); do
    		# r=${reps[${i}]}
    		# c=${concurrent[${j}]}

for r in $reps 
do
		for c in $concurrent 
		do
	  		echo -e -n "${r}次${c}并发     " >> ${outputfile}
				siege -c ${r} -r ${c} --log=${outputfile} -f get
	  		sleep 1
    done
done

 

